package com.siyuanren.gcocp.web;

import com.siyuanren.gcocp.common.web.bean.Result;
import com.siyuanren.gcocp.dto.UserDTO;
import com.siyuanren.gcocp.dto.wx.WxUserInviteCourseDTO;
import com.siyuanren.gcocp.entity.WxUser;
import com.siyuanren.gcocp.entity.WxUserCourseExample;
import com.siyuanren.gcocp.entity.WxUserVoucher;
import com.siyuanren.gcocp.mapper.base.WxUserCourseMapper;
import com.siyuanren.gcocp.service.CourseService;
import com.siyuanren.gcocp.service.UserService;
import com.siyuanren.gcocp.service.UserVoucherService;
import com.siyuanren.gcocp.service.VoucherService;
import com.siyuanren.gcocp.web.wx.BaseWxController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Objects;

/**
 * Created by   anxing
 * Project_name gcocp-parent
 * Path         com.siyuanren.gcocp.web
 * Date         2018/6/12
 * Time         13:30
 * Description  用户相关接口
 */

@Slf4j
@Controller
@RequestMapping("/user")
public class UserController extends BaseWxController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserVoucherService userVoucherService;
    @Autowired
    private CourseService courseService;

    /**
     * 得到用户信息
     * @return
     */
    @ResponseBody
    @RequestMapping("getUserInfo")
    public Result getUserInfo() {
        UserDTO userInfo = userService.getUserInfo(getUserId());
        return new Result(userInfo);
    }

    /**
     * 返回正常优惠券
     * @return
     */
    @ResponseBody
    @RequestMapping("getNormalVoucherCard")
    public Result getNormalVoucherCard() {
        List<WxUserVoucher> normalVoucher = userVoucherService.getNormalVoucher(getUserId());
        return new Result(normalVoucher);
    }

    /**
     * 返回过期或使用过优惠券
     * @return
     */
    @ResponseBody
    @RequestMapping("getOverdueVoucherCard")
    public Result getOverdueVoucherCard() {
        List<WxUserVoucher> overdues = userVoucherService.getOverdueVoucher(getUserId());
        return new Result(overdues);
    }

    /**
     * 邀请页面
     */
    @RequestMapping("getUserInvite")
    @ResponseBody
    public Result getUserInvite(Model model) throws Exception {
        List<WxUserInviteCourseDTO> dtos = courseService.getUserInviteCourseList(getUserId());
        return new Result(dtos);
    }

}
